﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data;
using MySql.Data.MySqlClient;
using Utilities.QuickSql;
using System.Globalization;
using System.IO;

namespace showcolat
{
    
    public partial class Form_description : Form
    {
        MySqlDatabase db = new MySqlDatabase("localhost", "root", "", "showcolat");
        MySqlDatabase db2 = new MySqlDatabase("localhost", "root", "", "showcolat");
        public string id_serie;
        public Serie se;
       
        public Form_description()
        {
            InitializeComponent();
            
        }

        public Form_description(Serie s)
        {
            InitializeComponent();
            se = s;
            lab_nomSerie.Text = se.NomSerie.ToString();
            this.Text = se.NomSerie.ToString();
            lab_genre.Text += se.genre.ToString();
            lab_note.Text += se.Note.ToString() + "/10";
            textBox_desc.Text = se.Resume.ToString();
        }

        public Form_description(string id_serie)
        {
            InitializeComponent();
            this.id_serie = id_serie.ToString();
            lab_idSerie.Text = id_serie.ToString();
            /************requete***************/
            Table serie1 = db.QueryTable("SELECT S.id_serie, S.nom_serie, G.libelle, S.note, S.description FROM serie S INNER JOIN genre G ON G.id_genre = S.id_genre WHERE id_serie =  '" + id_serie.ToString() + "'");
            Int64 nb_episode = db2.QueryValue<Int64>("SELECT COUNT(id_episode) AS \"Nombre d'épisodes\" FROM episode AS E INNER JOIN saison AS S ON S.id_saison = E.id_saison INNER JOIN serie AS SE ON SE.id_serie = S.id_serie WHERE S.id_serie = '"+id_serie+"'");
            Int64 nb_saison = db2.QueryValue<Int64>("SELECT COUNT( id_saison ) AS \"Nombre de saisons\" FROM saison AS S INNER JOIN serie AS SE ON SE.id_serie = S.id_serie WHERE S.id_serie ='"+id_serie+"'");
            byte[] Img = db2.QueryValue<byte[]>("SELECT image FROM serie WHERE id_serie =  '" + id_serie + "'");
            /***********************************/
            pictureBox1.Image = Image.FromStream(new MemoryStream(Img));
            foreach (Record desc in serie1)
            {
                this.Text = desc[1].ToString();
                lab_nomSerie.Text = desc[1].ToString();
                lab_genre.Text += desc[2].ToString();
                lab_note.Text += desc[3].ToString() + "/10";
                textBox_desc.Text = desc[4].ToString();
            }
            lab_NbSaison.Text += nb_saison.ToString();
            lab_NbEpisode.Text += nb_episode.ToString();
        }

        private void button_listEpisodes_Click(object sender, EventArgs e)
        {
            //if (se.NumSerie > 0)
            //{
                fen_liste episode = new fen_liste(se.NumSerie);
                episode.AutoScroll = true;
                episode.ShowDialog();
            //}
            /*else
            {
                fen_liste episode = new fen_liste(id_serie);
                episode.AutoScroll = true;
                episode.ShowDialog();
            }*/
        }
    }
}
